﻿<%@ Page Language="C#" AutoEventWireup="true" Theme="Default" CodeBehind="GaoPaiUpload.aspx.cs" Inherits="Web.Pages.YongShui._13.LAIHANGL.GAOPAIUPLOAD" %>
<%@ Register Assembly="DevExpress.Web.v15.2, Version=15.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script type="text/javascript">

        var DeviceMain;//主头
        var DeviceAssist;//副头
        var VideoMain;//主头
        var VideoAssist;//副头
        var HaoMiao = 0;
        var HM;
        var PicPath;

        function plugin() {
            return document.getElementById('view1');
        }
        function MainView() {
            return document.getElementById('view1');
        }
        function addEvent(obj, name, func) {
            if (obj.attachEvent) {
                obj.attachEvent("on" + name, func);
            } else {
                obj.addEventListener(name, func, false);
            }
        }
        function OpenVideo() {

            if (VideoMain == null) {
                Load();
            }
            OpenVideoMain();

        }
        function CloseVideo() {
            CloseVideoMain();
        }
        function CloseVideoMain() {
            //Unload();
            if (VideoMain) {
                plugin().Video_Release(VideoMain);
                VideoMain = null;

                MainView().View_SetText("", 0);
            }
        }


        function OpenVideoMain() {
            CloseVideoMain();

            if (!DeviceMain)
                return;
            var SelectType = 2;
            //分辨率 目前只能调到3 ,2或1加载不出来
            var nResolution = 3;            
            VideoMain = plugin().Device_CreateVideo(DeviceMain, nResolution, SelectType);           
            if (VideoMain) {                
                MainView().View_SelectVideo(VideoMain);
                MainView().View_SetText("正在打开高拍仪，请稍等...", 0);
                BtnGaoPaiY.SetEnabled(true);
                MainView().View_SetAdapt(true);
                //HM=self.setInterval("SetColor()", 1);               
            }            
        }
        function SetColor() {
            HaoMiao++;
            if (HaoMiao < 5000) {
                plugin().Video_EnableGray(VideoMain);
            }
            else {                
                HM = window.clearInterval(HM);
            }
            
        }
        function Load() {

            //设备接入和丢失
            //type设备类型， 1 表示视频设备， 2 表示音频设备
            //idx设备索引
            //dbt 1 表示设备到达， 2 表示设备丢失
            
            addEvent(plugin(), 'DevChange', function (type, idx, dbt) {
                if (1 == type)//视频设备
                {
                    if (1 == dbt)//设备到达
                    {
                        var deviceType = plugin().Global_GetEloamType(1, idx);
                        if (1 == deviceType) //主摄像头
                        {
                            if (null == DeviceMain) {
                                DeviceMain = plugin().Global_CreateDevice(1, idx);
                                if (DeviceMain) {
                                   

                                    OpenVideoMain();
                                }
                            }
                        } else {
                            alert(deviceType);
                        }
                    }
                    else if (2 == dbt)//设备丢失
                    {

                    }
                }
            });

            MainView().Global_SetWindowName("view");

            var ret;
            ret = plugin().Global_InitDevs();
            if (VideoMain == undefined) {
             //   alert("高拍仪未连接");
                BtnGaoPaiY.SetEnabled(false);
            }
            else {
               
            }
           
        }

        function Unload() {
           
            if (VideoMain) {
                MainView().View_SetText("", 0);
                plugin().Video_Release(VideoMain);
                VideoMain = null;
                plugin().Device_Release(DeviceMain);
            }
           
            plugin().Global_DeinitMagneticCard();
            plugin().Global_DeinitReader();
            plugin().Global_DeinitBiokey();
            plugin().Global_DeinitIdCard();
            plugin().Global_DeinitOcr();
            plugin().Global_DeinitDevs();
        }

        function ScanToHttpServer() {
            if (VideoMain) {
                var img = plugin().Video_CreateImage(VideoMain, 0, MainView().View_GetObject());
                var fwq = "";
                if (img) {
                    var http = plugin().Global_CreateHttp(window.location.href.split('?')[0] + "?type=upload&txtname=" + escape(Getparms("txtname")) + "&txtvalue=" + Getparms("txtvalue") + "&urltype=" + Getparms("urltype") + "&yonghuh=" + Getparms("yonghuh") + "&userId=" + Getparms("userId") + "&laihanbh=" + Getparms("laihanbh"));//asp服务器demo地址
                    if (http) {
                        var b = plugin().Http_UploadImage(http, img, 2, 0, "1.jpg");

                        if (b) {
                            CloseGP();
                            alert("上传成功");
                            // plugin().Image_Release(img);
                            //opene
                            window.close();
                        }
                        else {
                            alert("上传失败");
                        }

                        plugin().Http_Release(http);
                    }

                    plugin().Image_Release(img);
                }
             
            }

        }
        function Getparms(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        function ChangeVideoSize()
        {
            
        }

        function CloseGP()
        {
            
            try
            {
                var open = window.opener;
               
               //open.SetSelectValue(Getparms("index"));
                open.GaoPaiSC();

                //if (typeof (window.dialogArguments.SetSelectValue) == "function") {
                //    window.dialogArguments.SetSelectValue(Getparms("index"));
                //}
                //if (typeof (window.dialogArguments.GaoPaiSC) == "function") {
                //    window.dialogArguments.GaoPaiSC();
                //}
            }
            catch(ex)
            {
            
            }
           
        }
    </script>
</head>
<body onload="Load()" onunload="Unload()"  onresize="ChangeVideoSize()" style="overflow:hidden">
    <form id="form1" runat="server">
        <dx:ASPxHiddenField ID="hideV" runat="server"></dx:ASPxHiddenField>
        <div id="gp" style="width: 100%;">
            <div class="tabletitle1">
                高拍仪
            </div>
            <div>

                <div  style="text-align: center">
                    <table style="width: 100%">
                        <tr>

                            <td >

                                <object id="view1" type="application/x-eloamplugin" width="600" height="450" name="view"></object>

                            </td>
                            
                        </tr>

                    </table>

                </div>

            </div>
            <table style="width: 100%;">

                <tr>
                    <td align="center">

                        <dx:ASPxButton ID="BtnQR" AutoPostBack="false" ClientInstanceName="BtnGaoPaiY" runat="server"  Text="确定">
                            <ClientSideEvents Click="function(){ScanToHttpServer();}" />
                        </dx:ASPxButton>
                        <dx:ASPxButton ID="BtnQX" runat="server" Text="取消" AutoPostBack="false">
                            <ClientSideEvents Click="function(s,e){
                                
                                window.close();
                               
                                }" />
                        </dx:ASPxButton>
                    </td>

                </tr>
            </table>
        </div>
    </form>
</body>
</html>
